package com.onenine.app.view;

import android.content.Context;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.ActivityCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.onenine.app.R;
import com.onenine.common.util.ApUtils;


/**
 * 创建时间：2018/5/17 0017 17:46
 * 创建人：fly
 * 功能描述：单点选择控件
 */
public class SingleSelectView extends RelativeLayout {

    private ImageView mIvIndic;
    private TextView mTvLeft;
    private TextView mTvRight;

    public SingleSelectView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SingleSelectView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        if (needLayoutInflate()) {
            inflate(context, R.layout.layout_single_select, this);
        }
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        int lrPadding = getResources().getDimensionPixelSize(R.dimen.dp21);
        setBackgroundResource(R.drawable.ripple_list_item_color_bg);
        setPadding(lrPadding, 0, lrPadding, 0);
        mIvIndic = findViewById(R.id.iv_indic);
        mTvLeft = findViewById(R.id.tv_left);
        mTvRight = findViewById(R.id.edt_right);
    }

    protected boolean needLayoutInflate() {
        return true;
    }

    public void setLeftIndicateImage(@DrawableRes int resId) {
        mIvIndic.setImageResource(resId);
        mIvIndic.setVisibility(View.VISIBLE);
    }

    public void setLeftText(@StringRes int stringId) {
        setLeftText(getContext().getString(stringId));
    }

    public void setLeftText(String text) {
        mTvLeft.setText(text);
    }

    public void setLeftTextColor(@ColorRes int color) {
        mTvLeft.setTextColor(ActivityCompat.getColor(ApUtils.getApp(), color));
    }

    public void setRightText(@StringRes int stringId) {
        setRightText(getContext().getString(stringId));
    }

    public void setRightText(String text) {
        mTvRight.setText(text);
    }

    public void setRightTextTag(Object tag) {
        mTvRight.setTag(tag);
    }

    public void setRightHint(String hint) {
        mTvRight.setHint(hint);
    }

    public void setRightText(@StringRes int stringId, OnClickListener onClickListener) {
        setRightText(getContext().getString(stringId), onClickListener);
    }

    public void setNoArrayRightLogo() {
        mTvRight.setCompoundDrawables(null, null, null, null);
    }

    public void setRightText(String text, OnClickListener onClickListener) {
        mTvRight.setHint(text);
        setOnClickListener(onClickListener);
    }

    public void setRightTextColor(@ColorRes int color) {
        mTvRight.setTextColor(ActivityCompat.getColor(ApUtils.getApp(), color));
    }

    public String getRightText() {
        return mTvRight.getText().toString();
    }

    public String getLeftText() {
        return mTvLeft.getText().toString();
    }

    public String getRightHint() {
        return mTvRight.getHint().toString();
    }

    public Object getRightTextTag() {
        return mTvRight.getTag();
    }

}
